/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package golftourcalculator.dialogs;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

/**
 * FXML Controller class
 *
 * @author Martin
 */
public class FXMLAddTournamentDialogController implements Initializable {
    
    @FXML
    TextField tournamentNameTextField;
    
    @FXML
    TextField nettoTextField;
    
    @FXML
    TextField bruttoTextField;
    
    String tournamentName;
    String idNetto;
    String idBrutto;
    boolean commit;
    Stage dialogStage;
    
    @FXML
    private void cancelHandleAction(ActionEvent event) {
        this.commit = false;
        
        this.dialogStage.close();
    }
    
    @FXML
    private void addHandleAction(ActionEvent event) {
        this.tournamentName = this.tournamentNameTextField.getText();
        this.idNetto = this.nettoTextField.getText();
        this.idBrutto = this.bruttoTextField.getText();
        this.commit = true;
        
        // TODO checks
        
        this.dialogStage.close();
    }
    
    /**
     * Sets the stage of this dialog.
     * @param dialogStage
     */
    public void setDialogStage(Stage dialogStage) {
        this.dialogStage = dialogStage;
    }
    
    public String getTournamentName() {
        return this.tournamentName;
    }
    public String getNetto() {
        return this.idNetto;
    }
    
    public String getBrutto() {
        return this.idBrutto;
    }
    
    public boolean getCommit() {
        return this.commit;
    }
    
    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        this.tournamentName = new String();
        this.idBrutto = new String();
        this.idNetto = new String();
        this.commit = false;
        
        // for testing puposes only
        this.tournamentNameTextField.setText("Test");
        this.bruttoTextField.setText("http://cgf.cz/TournResultCategory.aspx?IDTournCategory=418176665");
        this.nettoTextField.setText("http://cgf.cz/TournResultCategory.aspx?IDTournCategory=418176667;http://cgf.cz/TournResultCategory.aspx?IDTournCategory=418176669");
    }    
    
}
